#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, k, p;
    cin >> n >> k >> p;

    vector<int> color(n);
    vector<int> cost(n);
    for (int i = 0; i < n; ++i) {
        cin >> color[i] >> cost[i];
    }

    vector<int> cnt(k, 0);
    vector<int> sum(k, 0);
    int last = -1;
    long long ans = 0;

    for (int i = 0; i < n; ++i) {
        int c = color[i];
        cnt[c]++;
        if (cost[i] <= p) {
            last = i;
            for (int j = 0; j < k; ++j) {
                sum[j] = cnt[j];
            }
        }
        if (last != -1) {
            if (cost[i] <= p) {
                ans += sum[c] - 1;
            } else {
                ans += sum[c];
            }
        }
    }

    cout << ans << endl;
    return 0;
}
